<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/file-upload.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/form/FileUploadField.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GroupSummary.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/RowExpander.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/EditableItem.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/RangeMenu.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GridFilters.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/Filter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
        <script type="text/javascript" src="../../scripts/selectPantone.js">
        </script>
		<script type="text/javascript" src="../../scripts/selectButton.js">
        </script>
        <script type="text/javascript">
            var orderMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.order');
			var fcMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomer');
			var fMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.factory');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
			var buttonMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.accessorybutton');
			var colorMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.pantonecolor');
            
            var ctDesignTypeXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtDesignType');
            var ctYesnoXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtYesno');
            var customerXmlLoader = new xmlLoader('../../servlet/BiFranceCustomerServlet?action=5');
 			var ctSeasonNumberXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtSeasonNumber');
 			var ctSendByXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtSendBy');
            
            var ctMaterialTypeStore;
            var ctYesnoStore;
			var customerStore;
			
			var ctSeasonNumberStore;
			var ctSeasonNumberCombo;
			var ctSendByCombo;
			var isCustomerSubmitCombo;
			var isColorApprovedCombo;

			var selectButtonCallback = function(biButtonId, biButtonReference, customerName, customerDepartment, customerReference, customerColor, 
												factoryNameCN, factoryReference,factoryColor,addressFactory, photo1Name, photo2Name, photo3Name, foo, factoryNameEN){
				Ext.getCmp('biButtonId').setValue(biButtonId);
				Ext.getCmp('biButtonReference').setValue(biButtonReference);
				Ext.getCmp('customerName').setValue(customerName);
				Ext.getCmp('customerDepartment').setValue(customerDepartment);
				Ext.getCmp('customerReference').setValue(customerReference);
				Ext.getCmp('customerColor').setValue(customerColor);
				Ext.getCmp('factoryNameCN').setValue(factoryNameCN);
				Ext.getCmp('factoryNameEN').setValue(factoryNameEN);
				Ext.getCmp('factoryReference').setValue(factoryReference);
				Ext.getCmp('factoryColor').setValue(factoryColor);				
				Ext.getCmp('deliveryAddress').setValue(addressFactory);
				
				document.getElementById('customImg').src =  '../../_temp/' + photo1Name;
				document.getElementById('customImg1').src =  '../../_temp/' + photo2Name;
				document.getElementById('customImg2').src =  '../../_temp/' + photo3Name;
			}
			
			var setReference = function(){
				var maxReferenceIndextXmlLoader = new xmlLoader('../../servlet/OrderButtonServlet?action=10');
				var maxIndex = maxReferenceIndextXmlLoader.getValueByTagName('item');
				//alert(maxIndex);
				document.getElementById('referenceIndex').value = maxIndex;
				document.getElementById('reference').value = 'FB-' + maxIndex;
			}
			
            Ext.onReady(function(){
                Ext.QuickTips.init();
                Ext.form.Field.prototype.msgTarget = 'side';
                
                var idValue = getPrarmeterValue(window.location, 'id');
                var startPage = getPrarmeterValue(window.location, 'startPage');
                
                ctDesignTypeStore = new Ext.data.Store({
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, ['code', 'description']),
                    data: ctDesignTypeXmlLoader.getXml()
                });
				
                ctYesnoStore = new Ext.data.Store({
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, ['code', 'description']),
                    data: ctYesnoXmlLoader.getXml()
                });
                
                customerStore = new Ext.data.Store({
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, ['id', 'name', 'department']),
                    data: customerXmlLoader.getXml()
                });
                
                 ctSeasonNumberStore = new Ext.data.Store({
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, [ 
                    'code', 'description']),
					data: ctSeasonNumberXmlLoader.getXml()
                });
                
                ctDesignTypeCombo = new Ext.form.ComboBox({
                    fieldLabel: orderMessage.get('ui.order.designtype'),
                    id: 'ctDesignType',
                    name: 'ctDesignType',
                    allowBlank: false,
                    blankText: message.get('message.edit.noblank'),
                    editable: false,
                    store: ctDesignTypeStore,
                    valueField: 'code',
                    displayField: 'description',
                    triggerAction: 'all',
                    emptyText: message.get('message.combo.pleaseselect'),
                    selectOnFocus: true,
                    mode: 'local'
                });
                
                isConfirmedCombo = new Ext.form.ComboBox({
                    fieldLabel: orderMessage.get('ui.order.isconfirmed'),
                    id: 'isConfirmed',
                    name: 'isConfirmed',
                    allowBlank: false,
                    blankText: message.get('message.edit.noblank'),
                    editable: false,
                    store: ctYesnoStore,
                    valueField: 'code',
                    displayField: 'description',
                    triggerAction: 'all',
                    emptyText: message.get('message.combo.pleaseselect'),
                    selectOnFocus: true,
                    mode: 'local',
					listeners: {
						select: {
							fn: function (thisCombo, record,index){
								var isConfirmed = isConfirmedCombo.getValue();
								if(isConfirmed == '01'){
									Ext.getCmp('confirmedDate').enable();
									Ext.getCmp('deliveryQuantity').enable();
									Ext.getCmp('deliveryDate').enable();
								}else{
									Ext.getCmp('confirmedDate').disable();
									Ext.getCmp('deliveryQuantity').disable();
									Ext.getCmp('deliveryDate').disable();
								}
							}
						}
					}
                });
                
                ctSeasonNumberCombo = new Ext.form.ComboBox({
                    fieldLabel: message.get('message.edit.seasonnumber'),
                    id: 'ctSeasonNumber',
                    name: 'ctSeasonNumber',
                    allowBlank: false,
                    blankText: message.get('message.edit.noblank'),
                    valueField: 'code',
                    typeAhead: true,
                    store: ctSeasonNumberStore,
                    displayField: 'description',
                    forceSelection: true,
                    triggerAction: 'all',
                    emptyText: message.get('message.combo.pleaseselect'),
                    selectOnFocus: true,
                    mode: 'local'
                });
                
                var orderButtonForm = new Ext.FormPanel({
                    labelAlign: 'left',
                    url: '../../servlet/OrderButtonServlet?action=1',
                    frame: true,
                    title: orderMessage.get('ui.order.editbutton'),
                    bodyStyle: 'padding:5px 5px 5px 5px;margin-top: 2px;',
                    width: '100%',
                    labelWidth: 125,
                    reader: new Ext.data.XmlReader({
                        record: 'item'
                    }, [{
                        name: 'id',
                        mapping: 'id'
                    }, {
                        name: 'reference',
                        mapping: 'reference'
                    }, {
                        name: 'referenceIndex',
                        mapping: 'referenceIndex'
                    }, {
                        name: 'ctDesignType',
                        mapping: 'ctDesignType'
                    }, {
                        name: 'ctSeasonNumber',
                        mapping: 'ctSeasonNumber'
                    }, {
                        name: 'launchDate',
                        mapping: 'launchDate'
                    }, {
                        name: 'biButtonId',
                        mapping: 'biButtonId'
                    }, {
                        name: 'biButtonReference',
                        mapping: 'biButtonReference'
                    }, {
                        name: 'customerName',
                        mapping: 'customerName'
                    }, {
                        name: 'customerDepartment',
                        mapping: 'customerDepartment'
                    }, {
                        name: 'customerReference',
                        mapping: 'customerReference'
                    }, {
                        name: 'customerColor',
                        mapping: 'customerColor'
                    }, {
                        name: 'factoryNameCN',
                        mapping: 'factoryNameCN'
                    }, {
                        name: 'factoryNameEN',
                        mapping: 'factoryNameEN'
                    }, {
                        name: 'factoryReference',
                        mapping: 'factoryReference'
                    }, {
                        name: 'factoryColor',
                        mapping: 'factoryColor'
                    }, {
                        name: 'orderQuantity',
                        mapping: 'orderQuantity'
                    }, {
                        name: 'isConfirmed',
                        mapping: 'isConfirmed'
                    }, {
                        name: 'confirmedDate',
                        mapping: 'confirmedDate'
                    }, {
                        name: 'deliveryQuantity',
                        mapping: 'deliveryQuantity'
                    }, {
                        name: 'deliveryDate',
                        mapping: 'deliveryDate'
                    }, {
                        name: 'deliveryAddress',
                        mapping: 'deliveryAddress'
                    },{
                        name: 'comment',
                        mapping: 'comment'
                    },{
                        name: 'photo1Name',
                        mapping: 'photo1Name'
                    },{
                        name: 'photo2Name',
                        mapping: 'photo2Name'
                    },{
                        name: 'photo3Name',
                        mapping: 'photo3Name'
                    }]),
                    //reader: msItemXMLReader,
                    items: [{
                        id: 'id',
                        name: 'id',
                        xtype: 'hidden'
                    },{
                        id: 'biButtonId',
                        name: 'biButtonId',
                        xtype: 'hidden'
                    },{
                        id: 'referenceIndex',
                        name: 'referenceIndex',
                        xtype: 'hidden'
                    },{
                        id: 'photoName',
                        name: 'photoName',
                        xtype: 'hidden'
                    },{
                        id: 'photo1Name',
                        name: 'photo1Name',
                        xtype: 'hidden'
                    },{
                        id: 'photo2Name',
                        name: 'photo2Name',
                        xtype: 'hidden'
                    },{
                        id: 'photo3Name',
                        name: 'photo3Name',
                        xtype: 'hidden'
                    }, {
                        layout: 'column',
                        items: [{
                            columnWidth: .33,
                            layout: 'form',
                            items: [ctDesignTypeCombo,{
                                id: 'reference',
                                name: 'reference',
                                fieldLabel: orderMessage.get('ui.order.reference'),
                                xtype: 'textfield',
                                allowBlank: false,
                                blankText: message.get('message.edit.noblank'),
                                anchor: '86%',
                                width: '90%',
                                maxLength: 64,
								listeners: {
                                        'render': {
                                            fn: function(){
                                                Ext.getCmp('reference').getEl().on('click', function(){
                                                    setReference();
                                                }, this);
                                            },
                                            scope: this
                                        }
                                    }
                            },{
                                id: 'biButtonReference',
                                name: 'biButtonReference',
                                fieldLabel: buttonMessage.get('ui.accessorybutton.reference'),
                                xtype: 'textfield',
                                allowBlank: false,
                                blankText: message.get('message.edit.noblank'),
                                emptyText: message.get('message.combo.pleaseselect'),
                                anchor: '86%',
                                width: '90%',
                                maxLength: 64,
								readOnly: true,
								listeners: {
                                        'render': {
                                            fn: function(){
                                                Ext.getCmp('biButtonReference').getEl().on('click', function(){
                                                	selectButton(selectButtonCallback);
                                                }, this);
                                            },
                                            scope: this
                                        }
                                    }
                            }]
                        }, {
                            columnWidth: .33,
                            layout: 'form',
                            items: [ctSeasonNumberCombo,{
                                id: 'customerName',
                                name: 'customerName',
                                fieldLabel: fcMessage.get('ui.francecustomer.name'),
                                xtype: 'textfield',
                                blankText: message.get('message.edit.noblank'),
                                anchor: '86%',
                                width: '90%',
                                maxLength: 64,
								readOnly: true
                            },{
                                id: 'customerDepartment',
                                name: 'customerDepartment',
                                fieldLabel: fcMessage.get('ui.francecustomer.department'),
                                xtype: 'textfield',
                                blankText: message.get('message.edit.noblank'),
                                anchor: '86%',
                                width: '90%',
                                maxLength: 64,
								readOnly: true
                            },{
                                id: 'customerReference',
                                name: 'customerReference',
                                fieldLabel: message.get('message.edit.customerreference'),
                                xtype: 'textfield',
                                blankText: message.get('message.edit.noblank'),
                                anchor: '86%',
                                width: '90%',
                                maxLength: 64,
								readOnly: true
                            },{
                                id: 'customerColor',
                                name: 'customerColor',
                                fieldLabel: colorMessage.get('ui.pantonecolor.customercolor'),
                                xtype: 'textfield',
                                blankText: message.get('message.edit.noblank'),
                                anchor: '86%',
                                width: '90%',
                                maxLength: 64,
								readOnly: true
                            }]
                        }, {
                            columnWidth: .33,
                            layout: 'form',
                            items: [{
									id: 'launchDate',
                                    name: 'launchDate',
                                    fieldLabel: orderMessage.get('ui.order.launchdate') + "(d/m/Y)",
                                    xtype: 'datefield',
                                    anchor: '70%',
                                    allowBlank: false,
                                    blankText: message.get('message.edit.noblank')
                             },{
                                id: 'factoryNameCN',
                                name: 'factoryNameCN',
                                xtype: 'textfield',
                                fieldLabel: fMessage.get('ui.factory.name'),
                                anchor: '86%',
								width: '90%',
                                maxLength: 256,
                                maxLengthText: message.get('message.edit.toolong'),
								readOnly: true
                            },{
                                id: 'factoryNameEN',
                                name: 'factoryNameEN',
                                xtype: 'textfield',
                                fieldLabel: '',
                                labelSeparator: '',
                                anchor: '86%',
								width: '90%',
                                maxLength: 256,
                                maxLengthText: message.get('message.edit.toolong'),
								readOnly: true
                            },{
                                id: 'factoryReference',
                                name: 'factoryReference',
                                fieldLabel: message.get('message.edit.factoryreference'),
                                xtype: 'textfield',
                                blankText: message.get('message.edit.noblank'),
                                anchor: '86%',
                                width: '90%',
                                maxLength: 64,
								readOnly: true
                            },{
                                id: 'factoryColor',
                                name: 'factoryColor',
                                fieldLabel: colorMessage.get('ui.pantonecolor.factorycolor'),
                                xtype: 'textfield',
                                blankText: message.get('message.edit.noblank'),
                                anchor: '86%',
                                width: '90%',
                                maxLength: 64,
								readOnly: true
                            }]
                        }]
                    },{
						xtype: 'fieldset',
						collapsible: true,
						title: orderMessage.get('ui.order.button'),
						autoHeight: true,
						items: [{
                            layout: 'column',
                            items: [{
                                columnWidth: .33,
                                layout: 'form',
                                items: [{
									xtype:'numberfield',
				                    fieldLabel: orderMessage.get('ui.order.orderquantity'),
				                    name: 'orderQuantity',
				                    anchor:'90%',
									allowBlank: false,
                        			blankText: message.get('message.edit.noblank'),
									maxLength: 64,
									tabIndex: 1
								},{
									xtype:'numberfield',
				                    fieldLabel: orderMessage.get('ui.order.deliveryquantity'),
				                    id: 'deliveryQuantity',
				                    name: 'deliveryQuantity',
				                    anchor:'90%',
									allowBlank: false,
                        			blankText: message.get('message.edit.noblank'),
									maxLength: 64,
									tabIndex: 1
								}]
							},{
                                columnWidth: .33,
                                layout: 'form',
                                items: [isConfirmedCombo,{
                            		id:'deliveryDate',
                                    name: 'deliveryDate',
                                    fieldLabel: orderMessage.get('ui.order.deliverydate') + "(d/m/Y)",
                                    xtype: 'datefield',
                                    anchor: '70%',
                                    allowBlank: false,
                                    blankText: message.get('message.edit.noblank')
                             }]
							},{
                                columnWidth: .33,
                                layout: 'form',
                                items: [{
                            		id:'confirmedDate',
                                    name: 'confirmedDate',
                                    fieldLabel: orderMessage.get('ui.order.confirmeddate') + "(d/m/Y)",
                                    xtype: 'datefield',
                                    anchor: '70%',
                                    allowBlank: false,
                                    blankText: message.get('message.edit.noblank')
                             }]
							}]
						},{
	                        fieldLabel: orderMessage.get('ui.order.deliveryaddress'),
	                        id: 'deliveryAddress',
	                        name: 'deliveryAddress',
	                        xtype: 'textarea',
	                        maxLength: 512,
	                        width: '90%',
	                        maxLengthText: message.get('message.edit.toolong')
	                    }]
					}, {
                        fieldLabel: message.get('message.edit.comment'),
                        name: 'comment',
                        xtype: 'textarea',
                        maxLength: 512,
                        width: '90%',
                        maxLengthText: message.get('message.edit.toolong')
                    }],
                    
                    buttons: [{
                        text: message.get('message.edit.save'),
                        handler: function(){
                            if (orderButtonForm.getForm().isValid()) {
                            
                            	if(idValue == null){
                            		setReference();
                            	}
                            
                                document.getElementsByName('ctDesignType')[0].value = ctDesignTypeCombo.getValue();
                                document.getElementsByName('ctSeasonNumber')[0].value = ctSeasonNumberCombo.getValue();
								document.getElementsByName('isConfirmed')[0].value = isConfirmedCombo.getValue();
								
                                orderButtonForm.getForm().submit({
                                    method: 'post',
                                    success: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.successful'));
                                        orderButtonForm.getForm().reset();
                                    },
                                    failure: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.unsuccessful'));
                                    }
                                });
                            }
                        }
                    }, {
                        text: message.get('message.edit.reset'),
                        handler: function(){
                            orderButtonForm.getForm().reset();
                        }
                    }, {
                        text: message.get('message.edit.cancel'),
                        handler: function(){
                            if (startPage != null) {
                                window.location = 'order_button_list.html?startPage=' + startPage;
                            }
                            else {
                                window.location = 'order_button_list.html';
                            }
                        }
                    }]
                });
                
                orderButtonForm.render('orderButton');
                
                new Ext.Resizable('customImg', {
                    wrap: true,
                    pinned: true,
                    dynamic: true,
                    handles: 'all',
                    draggable: true
                });
                
                new Ext.Resizable('customImg1', {
                    wrap: true,
                    pinned: true,
                    dynamic: true,
                    handles: 'all',
                    draggable: true
                });
                
                new Ext.Resizable('customImg2', {
                    wrap: true,
                    pinned: true,
                    dynamic: true,
                    handles: 'all',
                    draggable: true
                });
                
                if (idValue != null) {
                    document.getElementById('id').value = idValue;
                    orderButtonForm.getForm().load({
                        url: '../../servlet/OrderButtonServlet?action=3&id=' + idValue,
                        waitMsg: Ext.LoadMask.prototype.msg,
                        success: function(form, action){
                        	isConfirmedCombo.fireEvent('select');
							
							document.getElementById('customImg').src =  '../../_temp/' + document.getElementById('photo1Name').value;
							document.getElementById('customImg1').src =  '../../_temp/' + document.getElementById('photo2Name').value;
							document.getElementById('customImg2').src =  '../../_temp/' + document.getElementById('photo3Name').value;
                        }
                    });
                }
            });
        </script>
    </head>
    <body>
        <div id="orderButton">
        </div>
        <img id="customImg" src="../../_temp/noimage.gif"
			style="position: absolute; left: 10%; width: 250px;" />
		<img id="customImg1" src="../../_temp/noimage.gif"
			style="position: absolute; left: 40%; width: 250px;" />
		<img id="customImg2" src="../../_temp/noimage.gif"
			style="position: absolute; left: 70%; width: 250px;" />
    </body>
</html>